Skip to content

Make parser's #inspect work in non-main Ractors - #262

Open
y-yagi wants to merge 1 commit into
ruby:masterfrom
y-yagi:fix_parser_inspect_in_ractor
Open

y-yagi wants to merge 1 commit into
ruby:masterfrom
y-yagi:fix_parser_inspect_in_ractor

Conversation

@y-yagi

@y-yagi y-yagi commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

URI::RFC3986_PARSER.inspect and URI::RFC2396_PARSER.inspect raised Ractor::IsolationError when called from a non-main Ractor:

Ractor.new { URI::RFC3986_PARSER.inspect }.value
#=> can not access class variables from non-main Ractors
#   (@@to_s from URI::RFC3986_Parser)

Ractor.new { URI::RFC2396_PARSER.inspect }.value
#=> can not access non-shareable objects in constant
#   URI::RFC2396_Parser::TO_S by non-main ractor

Both parsers kept Kernel.instance_method(:to_s) at the class level, in a class variable and in a constant respectively. An UnboundMethod is not shareable, so neither can be read from a non-main Ractor.

UnboundMethod is Ractor-shareable only Ruby 4.0. And, parser's inspect only for debug and performance isn't so important, I think

So this commit changes not to held the method and just call it in the method.

@y-yagi
y-yagi marked this pull request as ready for review September 9, 2026 09:55
@y-yagi
y-yagi force-pushed the fix_parser_inspect_in_ractor branch from 2dce201 to c39e987 Compare September 13, 2026 05:38
`URI::RFC3986_PARSER.inspect` and `URI::RFC2396_PARSER.inspect` raised
`Ractor::IsolationError` when called from a non-main Ractor:

    Ractor.new { URI::RFC3986_PARSER.inspect }.value
    #=> can not access class variables from non-main Ractors
    #   (@@to_s from URI::RFC3986_Parser)

    Ractor.new { URI::RFC2396_PARSER.inspect }.value
    #=> can not access non-shareable objects in constant
    #   URI::RFC2396_Parser::TO_S by non-main ractor

Both parsers kept `Kernel.instance_method(:to_s)` at the class level, in a
class variable and in a constant respectively. An `UnboundMethod` is not
shareable, so neither can be read from a non-main Ractor.

`UnboundMethod` is Ractor-shareable only Ruby 4.0. And, parser's inspect only for
debug and performance isn't so important, I think

So this commit changes not to held the method and just call it in the
method.
@y-yagi
y-yagi force-pushed the fix_parser_inspect_in_ractor branch from c39e987 to 0f8bde9 Compare September 13, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant